#include<stdio.h>
#include<dirent.h>

int main(int argc, char* argv[])
{
    DIR* dir;
    if (argc < 2)
        dir = opendir(".");
    else
        dir = opendir(argv[1]);

    while (1)
    {
        struct dirent* dire = readdir(dir);
        if (dire == NULL)
            break;
        switch (dire->d_type)
        {
            case DT_DIR:
                printf("DIR %s\n", dire->d_name);
                break;
            case DT_REG:
                printf("REG %s\n", dire->d_name);
                break;
        }
    }

    closedir(dir);
}